// 导航列表
var defaultList = [];
var defaultLock = 0;
function getDefaultList() {
	// type: 0不可选不可跳转 1可选可跳转 2可选不可跳转
	var list = [
		{"type": 0, "desc": "🎈网站类🎈", "url": ""},
		{"type": 1, "desc": "大米星球 - 影视网站", "url": "https://damvwx.wiki/"},
		{"type": 1, "desc": "DeepSeek - 深度求索", "url": "https://chat.deepseek.com/"},
		{"type": 1, "desc": "鸿梦云 - 云服务器", "url": "https://hmyun.com.cn/"},
		{"type": 1, "desc": "Cloudflare - 云平台", "url": "https://www.cloudflare-cn.com/"},
		{"type": 1, "desc": "CSDN - 博客", "url": "https://blog.csdn.net/weixin_47600880?type=blog"},
		{"type": 1, "desc": "Gitee - 基于Git的代码托管研发平台", "url": "https://gitee.com/"},
		{"type": 1, "desc": "Github - Where the world builds software", "url": "https://github.com/"},
		{"type": 0, "desc": "🛠️工具类🛠️", "url": ""},
		{"type": 1, "desc": "MD5 - 加密工具", "url": "https://www.toolhelper.cn/DigestAlgorithm/MD5"},
		{"type": 1, "desc": "Json - 格式化", "url": "https://www.toolhelper.cn/JSON/JSONFormat"},
		{"type": 1, "desc": "Sql - 格式化", "url": "https://www.toolhelper.cn/Format/SqlFormat"},
		{"type": 1, "desc": "Cron - 表达式生成器", "url": "https://www.toolscat.com/dev/cron"},
		{"type": 1, "desc": "Hex - 进制转换", "url": "https://tool.lu/hexconvert"},
		{"type": 1, "desc": "Timestamp - 时间戳", "url": "https://tool.lu/timestamp/"},
		{"type": 1, "desc": "Regex - 正则表达式工具", "url": "https://regexr-cn.com/"},
		{"type": 1, "desc": "String - 文本比对工具", "url": "https://www.jyshare.com/front-end/8006/"},
		{"type": 1, "desc": "QrCOde - 草料二维码生成器", "url": "https://cli.im/"},
		{"type": 1, "desc": "RGB - 颜色代码生成器", "url": "https://htmlcolorcodes.com/color-picker/"},
		{"type": 1, "desc": "CodeRun - 在线运行代码", "url": "https://www.toolhelper.cn/Code/Run?languageId=62"},
		{"type": 1, "desc": "Calculator - 计算器", "url": "https://www.toolhelper.cn/Digit/Calc"},
		{"type": 1, "desc": "WebSocket - 在线测试", "url": "http://wstool.jackxiang.com/"},
		{"type": 1, "desc": "QQ - 邮箱", "url": "http://mail.qq.com/"},
		{"type": 1, "desc": "Photopea - 在线PS", "url": "https://ps.xieniao.com/"},
		{"type": 1, "desc": "Maven - 中央仓库", "url": "https://mvnrepository.com/"},
		{"type": 1, "desc": "Docker - 官方镜像中心", "url": "https://hub.docker.com/"},
		{"type": 1, "desc": "Docker - 网易镜像中心", "url": "https://c.163yun.com/hub#/home"},
		{"type": 1, "desc": "Iconfont - 阿里巴巴矢量图标库", "url": "https://www.iconfont.cn/"},
		{"type": 1, "desc": "大米星球 - 发布页", "url": "https://dmxqshow.com/"},
		{"type": 1, "desc": "Temp-Mail", "url": "https://temp-mail.org/en/"},
		{"type": 1, "desc": "Free-Online-Phone", "url": "https://www.freeonlinephone.org/"},
		{"type": 1, "desc": "Data-Structure-Visualizations", "url": "https://www.cs.usfca.edu/~galles/visualization/Algorithms.html"},
		{"type": 0, "desc": "📖文档类📖", "url": ""},
		{"type": 1, "desc": "ThinkPHP - 开发手册", "url": "https://www.kancloud.cn/manual/thinkphp5/118003"},
		{"type": 1, "desc": "微信 - 官方文档", "url": "https://developers.weixin.qq.com/doc/"},
		{"type": 1, "desc": "企微 - 官方文档", "url": "https://developer.work.weixin.qq.com/document"},
		{"type": 1, "desc": "支付宝 - 开发文档", "url": "https://open.alipay.com/developmentDocument.htm"},
		{"type": 1, "desc": "Vue3 中文文档", "url": "https://www.javascriptc.com/vue3js/"},
		{"type": 1, "desc": "Node.js - 菜鸟教程", "url": "https://www.runoob.com/nodejs/nodejs-tutorial.html"},
		{"type": 1, "desc": "ElementUI - 文档", "url": "https://element-plus.org/zh-CN/#/zh-CN"},
		{"type": 1, "desc": "ECharts - 文档", "url": "https://echarts.apache.org/examples/zh/index.html"},
		{"type": 1, "desc": "码上登录 - API 文档", "url": "http://login.vicy.cn/apiWord.html"},
		{"type": 1, "desc": "Redis - 命令手册", "url": "https://www.redis.net.cn/order/"},
		{"type": 1, "desc": "HTTP - 状态码详解", "url": "https://www.toolscat.com/wiki/http"},
		{"type": 1, "desc": "Keycode - 键码对照表", "url": "https://tool.ip138.com/keycode/"},
		{"type": 1, "desc": "ASCII - 对照表", "url": "https://www.toolscat.com/wiki/ascii"},
		{"type": 1, "desc": "HTML - 特殊转义字符对照表", "url": "https://www.toolscat.com/wiki/html"},
		{"type": 1, "desc": "Content-Type - 参照表", "url": "https://www.toolscat.com/wiki/http-content-type"},
		{"type": 1, "desc": "Git - 提交规范", "url": "https://zhuanlan.zhihu.com/p/67804026"},
		{"type": 1, "desc": "代码随想录", "url": "https://programmercarl.com/"},
		{"type": 1, "desc": "开源 API 大全", "url": "https://api.aa1.cn/"},
		{"type": 1, "desc": "Java - 面试题十万字总结", "url": "https://www.aliyundrive.com/s/Sgy5cydiDsH"},
		{"type": 1, "desc": "Linux - 命令大全", "url": "https://linux.cmsblogs.cn/"},
		{"type": 1, "desc": "Learning Git Branching", "url": "https://learngitbranching.js.org/"},
		{"type": 0, "desc": "🍔软件类🍔", "url": ""},
		{"type": 1, "desc": "IDEA - Java 编辑器", "url": "https://www.jetbrains.com/idea/"},
		{"type": 1, "desc": "PhpStorm - PHP 编辑器", "url": "https://www.jetbrains.com/phpstorm/"},
		{"type": 1, "desc": "DataGrip - 数据库管理工具", "url": "https://www.jetbrains.com/zh-cn/datagrip/"},
		{"type": 1, "desc": "Sublime - 超轻量级文本编辑器", "url": "https://www.sublimetext.com/"},
		{"type": 1, "desc": "NxShell - 跨平台 SSH 终端工具", "url": "https://github.com/nxshell/nxshell/releases"},
		{"type": 1, "desc": "Windows - 终端工具", "url": "https://github.com/microsoft/terminal/releases"},
		{"type": 1, "desc": "Git - 版本管理工具", "url": "https://git-scm.com/download"},
		{"type": 1, "desc": "Sourcetree - Git 可视化工具", "url": "https://www.sourcetreeapp.com/"},
		{"type": 1, "desc": "Postman - API 接口测试神器", "url": "https://www.postman.com/downloads/"},
		{"type": 1, "desc": "Another - Redis 可视化工具", "url": "https://github.com/qishibo/AnotherRedisDesktopManager/releases"},
		{"type": 1, "desc": "WPS Office - 个人版", "url": "https://www.wps.cn/product/wps2016/"},
		{"type": 1, "desc": "Typora - Markdown 编辑器", "url": "http://www.itmind.net/13398.html"},
		{"type": 1, "desc": "向日葵 - 远程控制软件", "url": "https://sunlogin.oray.com/"},
		{"type": 1, "desc": "7-Zip - 压缩包解压工具", "url": "https://7-zip.org/"},
		{"type": 1, "desc": "Geek - 软件卸载工具", "url": "https://geekuninstaller.com/"},
		{"type": 1, "desc": "Everything - 文件查找工具", "url": "https://www.voidtools.com/zh-cn/"},
		{"type": 1, "desc": "Visual-NMP - PHP集成环境", "url": "https://visual-nmp.en.softonic.com/"},
		{"type": 1, "desc": "一元机场", "url": "https://yiyuan9.com/"},
		{"type": 1, "desc": "AD-钙奶", "url": "https://lydia.adgv.top/"},
		{"type": 1, "desc": "NATAPP - 内网穿透", "url": "https://natapp.cn/"},
		{"type": 1, "desc": "Byrut 二号宝藏网站", "url": "https://byrut.org/"},
		{"type": 1, "desc": "Windows - 激活工具", "url": "https://pan.baidu.com/s/1G9XTl2ngAPo8WlHhs8dkiQ?pwd=9j23"},
		{"type": 1, "desc": "IntelliJ - 激活工具", "url": "https://pan.baidu.com/s/1-VYOPcC9QNT-1_41gMxP5A?pwd=rzqa"},
		{"type": 1, "desc": "Lightroom - 预设包", "url": "https://www.bilibili.com/video/BV1mK411p7mK"},
		{"type": 1, "desc": "Lightroom - 调色工具", "url": "https://www.bilibili.com/video/BV1yE411J7iY/"}
	];
	if(defaultLock === 0) {
		defaultLock = 1; // 防止多次请求
		$.ajax({
			url: "/nav/getList",
			type: "get",
			success:function(res){
				if(res.code === 200 && res.data !== null) {
					defaultList = res.data;
					setSearchList(defaultList);
				}
			},
		});
	}
	return defaultList.length === 0 ? list : defaultList;
}
function setSearchList(searchList) {
    helangSearch.els.hotList.html(function () {
    	var flag = '&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;';
        var str = '';
        var num = 0;
        var arr = [0, 2, 3];
        $.each(searchList, function (index, item) {
			var temp = item.desc;
        	if(arr.indexOf(item.type) >= 0) {
        		if(item.type === 0) {
					temp = flag + '<strong><i>' + item.desc + '</i></strong>';
        		}
        		str +='<a style="padding: 10px">';
        	} else {
        		str +='<a href="' + item.url + '">';
        	}
        	if(item.type > 0) {
        		str +='<div class="list-num number">'+(++num)+'</div>';
        	}

            str += item.url !== '' ? "<img class='list-img' onerror='imgerrorfun();' loading='lazy' src="
                + getFavicon(item.url) + ">" : '';
            str +='<div class="list-url">' + temp + '</div>';
            str +='</a>';
        });
        return str;
    });
}

// 翻译
var fanyiUrl = 'https://fanyi.baidu.com/#en/zh/';
var fanyiErr = '<span style=\'user-select:none\'>百度翻译：<span style="color: red"><strong>接口请求超时~~</strong></span></span>';
var fanyiList = [{"type": 2, "desc": "<span style='user-select:none'>百度翻译：</span>请输入内容后回车发送 ~ ", "url": fanyiUrl}];
function getFanyiList() {return fanyiList;}
function setFanyiList() {
	if(typeof helangSearch === 'undefined') {
		return;
	}
	fanyiList[0].url = fanyiUrl + helangSearch.els.input.val();
	fanyiList[0].desc = '<span style="user-select:none">百度翻译：</span>正在翻译中，请稍后 ~ ';
	$.ajax({
		url: "/nav/getFanyiResult",
		type: "post",
		contentType: "application/json",
		data: JSON.stringify({
			keyword: helangSearch.els.input.val()
		}),
		success:function(res){
			if(helangSearch.searchIndex === 1) {
				if(res.code !== 200) {
					fanyiList[0].desc = fanyiErr;
					setEngineList();
					return;
				}
				fanyiList[0].desc = '<span style="user-select:none">百度翻译：</span><strong><i>' + res.data.value + '</i></strong>';
				setEngineList();
			}
		},
		error:function(res) {
			if(helangSearch.searchIndex === 1 && helangSearch.els.input.val() !== '') {
				fanyiList[0].desc = fanyiErr;
				setEngineList();
			}
		}
	});
	setEngineList();
}